package com.guoyh.bilbase.base.activity

import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.LayoutInflaterCompat
import com.guoyh.baseutils.file.ALPHA_20
import com.guoyh.baseutils.ext.getColorm
import com.ruffian.library.widget.iface.RHelper
import com.xuexiang.xui.utils.StatusBarUtils

/**
 * 作者　: hegaojian
 * 时间　: 2020/11/18
 * 描述　:
 */
abstract class BaseInitActivity : AppCompatActivity() {

    abstract val layoutId: Int

    lateinit var dataBindView: View

    var isSetFactorEd = false


    override fun onCreate(savedInstanceState: Bundle?) {
        toSetFactor()
        super.onCreate(savedInstanceState)
        setStatusColor()
    }

    fun toSetFactor() {
        if (isSetFactorEd) {
            return
        }

        val layoutInflater = LayoutInflater.from(this)
        LayoutInflaterCompat.setFactory(
            layoutInflater
        ) { parent, name, context, attrs ->
            var view: View? = null

//            val isCanClick = attrs.getAttributeBooleanValue(R.attr.canClick,false)

//            Loger.dd("===",isCanClick)

            //表明是自定义View
            if (name.contains("com.ruffian.library.widget")) {
                view = layoutInflater.createView(name, null, attrs);
            }

//            if (view == null) {
//                view = delegate.createView(parent, name, context, attrs)
//            }
//
//            val mAppArrays = context.obtainStyledAttributes(attrs, R.styleable.mAppAttr)
//            val isReClick = mAppArrays.getBoolean(R.styleable.mAppAttr_isReClick, false)
//            mAppArrays.recycle()
//            if (isReClick) {
//                view = delegate.createView(parent, name, context, attrs)
//                clickViews.add(view)
//            }


            view?.let {
                if (it is RHelper<*> && it.helper.useRipple()) {
                    if (it.helper.rippleColor == Color.RED) {
                        it.helper.rippleColor = getColorm("#333333", ALPHA_20)
                    }
                }
            }
            view
        }
        isSetFactorEd = true
    }

    fun setStatusColor() {
        StatusBarUtils.translucent(this)
        StatusBarUtils.setStatusBarLightMode(this)
    }

}